<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.app
 */
class AppController extends Controller {
	var $view = 'Theme';
	var $theme = 'default';
	var $helpers = array('Html', 'Form', 'Session', 'Paginator', 'Tree','Javascript','DatePicker');
	var $components = array(
						'Auth' => array(
							 'loginAction' => array('controller' => 'users', 'action' => 'login', 'admin' => false),
							'loginRedirect' => array('controller' => 'job_details', 'admin' => true),
							 'authorize' => 'actions',
							 'actionPath' => 'controllers/',
							 'authError' => 'You need to login before you can access this page.',
							 'loginError' => 'Email/Password do not match.'),
				 		'RequestHandler', 'Treetraverse', 'Session', 'RememberMe');
	
	function beforeFilter()
	{
		/*if (isset($_COOKIE["language"]))
		{
		$language = $_COOKIE["language"];
		}
		else
		{
		$language = 'jp';
		}
		include('views/themed/admin/pages/' .$language . '.ctp');*/
		//$this->Session->write('Config.language', 'jpn');
		//$this->Auth->allow('*');
	}
	
	function beforeRender() {
		$this->layout = ($this->RequestHandler->isAjax())? 'ajax': 'default';
		if(isset($this->params['admin'])) {
			 $this->theme = 'admin';
		}
	}
 	function getFileExtension($str) {
        $i = strrpos($str,".");
        if (!$i) { return ""; }
        $l = strlen($str) - $i;
        $ext = substr($str,$i+1,$l);
        return $ext;
    }
    
    function changeLanguage($language = null) 
	{
		if($language != NULL){
			$this->Session->write('Customer.language', $language);
			$this->Session->write('Config.language', $language);
		}else{
			$this->Session->write('Customer.language', 'eng');
			$this->Session->write('Config.language', 'eng');
		}

		//$this->EventBase->ProcessEvent('SwitchLanguage');
		
		if($redirect != null)
			$this->redirect($redirect);	
		else
			if(isset($_SERVER['HTTP_REFERER']))
				$this->redirect($_SERVER['HTTP_REFERER']);
			else
				$this->redirect('/');			
	}
}
